package com.briup.bms.common.config;

import com.briup.bms.web.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MVCConfig implements WebMvcConfigurer {

//	@Autowired
//	private FirstInterceptor firstInterceptor;
//	@Autowired
//	private SecondInterceptor secondInterceptor;

    @Autowired
    private AuthInterceptor authInterceptor;

    /**
     * 配置拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        WebMvcConfigurer.super.addInterceptors(registry);
//		registry.addInterceptor(secondInterceptor)
//				.addPathPatterns("/region/**");
//		registry.addInterceptor(firstInterceptor)
//				.addPathPatterns("/title/**","/region/**")
//				.excludePathPatterns("/title/by/condition");
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/title/**", "/region/**",
                        "/emp/**", "/customer/**", "/auth/**", "/dept/**", "/inventory/**",
                        "/order/**", "/product/**","/WareHouse/**");
    }


    /**
     * 配置跨域资源共享 cors
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*")
                .allowedHeaders("*")
                .allowedMethods("*");
    }
}
